import Vue from 'vue'
import Router from 'vue-router'
import XMain from '@/components/XMain'
import XHome from '@/components/XHome'
import XWork from '@/components/XWork'
import XLive from '@/components/XLive'
import XDiscover from '@/components/XDiscover'
import XApply from '@/components/XApply'
import XSupport from '@/components/XSupport'
import XNav from '@/components/XNav'
// import CForm from '@/components/CForm'
import { SArrival, SCompany, SVisa, STrain, SWork } from '@/components/support'
import { DShangHai, DChengDu, DChongQing, DQingDao, DXiaMen } from '@/components/discover'

import { routerNameConfig, titleConfig, needTitleArr } from '../config/title.config'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: routerNameConfig.app,
      component: XMain,
      redirect: '/home',
      children: [{
        path: 'home',
        name: routerNameConfig.home,
        component: XHome,
      }, {
        path: 'work',
        name: routerNameConfig.work,
        component: XWork,
      }, {
        path: 'live',
        name: routerNameConfig.live,
        component: XLive,
      }, {
        path: 'apply',
        name: routerNameConfig.apply,
        component: XApply,
      }, {
        path: 'support',
        name: routerNameConfig.support,
        component: XSupport,
        redirect: 'support/support_arrival',
        // tabs 切换的路由
        children: [{
          path: 'support_arrival',
          name: 'support_arrival',
          component: SArrival
        }, {
          path: 'support_company',
          name: 'support_company',
          component: SCompany
        }, {
          path: 'support_visa',
          name: 'support_visa',
          component: SVisa
        }, {
          path: 'support_train',
          name: 'support_train',
          component: STrain
        }, {
          path: 'support_work',
          name: 'support_work',
          component: SWork
        }]
      }],
    },
    {
      path: '/discover',
      name: routerNameConfig.discover,
      component: XDiscover,
      redirect: 'discover/shanghai',
      children: [{
        path: 'shanghai',
        name: 'shanghai',
        component: DShangHai
      }, {
        path: 'chengdu',
        name: 'chengdu',
        component: DChengDu
      }, {
        path: 'chongqing',
        name: 'chongqing',
        component: DChongQing
      }, {
        path: 'qingdao',
        name: 'qingdao',
        component: DQingDao
      }, {
        path: 'xiamen',
        name: 'xiamen',
        component: DXiaMen
      }]
    },
    {
      path: '/nav',
      name: routerNameConfig.nav,
      component: XNav
    },
    // {
    //   path: '/form',
    //   name: routerNameConfig.form,
    //   component: CForm
    // },
    {
      path: '**',
      redirect: '/home',
    }
  ]
})

router.afterEach((to, from, next) => {
  const name = to.name;
  if(needTitleArr.indexOf(name) !== -1) {
    document.title = titleConfig[name]
  }
})

export default router
